<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AI智能客服</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1，minimum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/customer/css/ai_service.cli.v2.css">
</head>
<body>
<div class="chat-container" id="app">
    <div class="layui-row">
        <div class="chat-box">

        </div>
    </div>
</div>
<script src="__STATIC__/common/js/jquery.min.js"></script>
<script src="__STATIC__/layui/layui.js"></script>
<script src="__STATIC__/common/js/ai_service.io.js"></script>
<script>

    $(function () {
        getChatLog("{$uid}", 1);
    });

    // 获取聊天记录
    function getChatLog(uid, page, flag, bottom) {

        $.getJSON('/seller/log/getChatLogDetail', {uid: uid, page: page}, function(res){
            if(0 == res.code && res.data.length > 0) {

                if(res.msg == res.total){
                    var _html = '<div class="clearfloat"><div class="author-name"><small>没有更多了</small></div><div style="clear:both"></div></div>';
                }else{
                    var _html = '<div class="clearfloat"><div class="author-name" data-page="' + parseInt(res.msg + 1)
                        + '" onclick="getMore(this)"><small class="chat-system">更多记录</small></div><div style="clear:both"></div></div>';
                }

                $.each(res.data, function (k, v) {
                    if(v.type == 'mine') {

                        _html += ai_service.showMyChatLog(v);
                    } else if(v.type == 'user'){

                        _html += ai_service.showMessage({time: v.create_time, avatar: v.from_avatar, content: v.content});
                    }
                });

                if(typeof flag == 'undefined'){
                    $(".chat-box").html(_html);
                }else{
                    $(".chat-box").prepend(_html);
                }

                ai_service.showBigPic();

                if(typeof bottom == 'undefined') {
                    wordBottom();
                }
            } else if (0 == res.code && res.data.length == '') {

                $(".chat-box").append(comQuestion);
            }
        });
    }

    // 获取更多的的记录
    function getMore(obj) {
        $(obj).remove();

        var page = $(obj).attr('data-page');

        getChatLog("{$uid}", page, 1, 1);
    }

    // 滚动到最底端
    function wordBottom() {
        var box = $(".chat-box");
        box.scrollTop(box[0].scrollHeight);
    }
</script>
</body>
</html>